import { useState,createContext, type Dispatch, type SetStateAction } from "react";
import ContextCom1 from "./ContextCom1";
import ContextCom2 from "./ContextCom2";
import type { UserInfo } from "../../apis/userinfo/type";

// 定义Context值的类型
interface ContextValue {
    counts: number;
    title:string,
    user:UserInfo,
    setCounts: (data:number)=>void;
  }

 export const Context= createContext<ContextValue | null>(null);
 

function UseContextDemo(){

    const [user]=useState<UserInfo>({})

    const [counts,setCounts]=useState(0);
    const [title]=useState("");


    return (
        <div>
            {counts}
            <button onClick={()=>setCounts(counts+1)}>++</button>
            <div>UseContextDemo</div>
            <Context.Provider value={{counts,setCounts,title,user}}> 

              <ContextCom1></ContextCom1>
               <ContextCom2></ContextCom2>

            </Context.Provider> 
      
            
        </div>
    )

}
export default UseContextDemo;